#include "Tower.hpp"
#include <GL\freeglut.h>

Tower::Tower()
{
  range_ = 50.0f;
}

Tower::~Tower()
{
}

void Tower::privateInit()
{

}

void Tower::privateRender()
{
  if( fireDelay_ > 0.0 )
  {
	glColor3f(.3f,0,0);
  }
  else
  {
	glColor3f(1,0,0);
  }
  

  //Mat4f rotation90;
  //setIdentity(rotation90);
  //rotateZ(rotation90, M_PI);
  //glMultMatrixf( &rotation90[0] );

  glPushMatrix();
  glTranslatef( 0, -5.0f, 0 );
  glScalef(1,0,1);
  glRotatef(90, 1, 0, 0);
  
  

  glutWireTorus( 1.0f, range_, 6, 16);
  glPopMatrix();

  //inverse(rotation90);
  //glMultMatrixf( &rotation90[0] );

  
  glutWireCube(10);
  glTranslatef(0,5,0);
  glutWireCube(5);
}


void Tower::privateUpdate()
{
  //! reduce firedelay
  fireDelay_ -= sslf_;
}


bool Tower::isInShotRange(boost::shared_ptr<Minion> minion)
{
  //! cannot shoot if still firedelay
  if( fireDelay_ > 0.0 ) return false;

  float distance = euclideanDistanceSquared( getPos(), minion->getPos() );
  float rangeSquared = range_ * range_;
  bool canShoot = false;
  if( distance < rangeSquared )
  {
	canShoot = true;
	fireDelay_ = 1.0f;
  }
  return canShoot;
}